<script setup>
import  useMenuStore  from '../store/modules/menu';
import { useRouter} from 'vue-router'
//接收父组件的数据
const props = defineProps(['menuData', 'index'])
//创建router实例
const router=useRouter()
//获取仓库数据
const menuStore =useMenuStore ();
//点击菜单，跳转路由
const handlClick=(item,active)=>{
//  console.log(item,'item');
 
 router.push(item.meta.path)
 

}


</script>

<template>
    <template v-for="(item, index) in props.menuData">
        <el-menu-item @click="handlClick(item,` ${props.index} - ${item.meta.id}`)" v-if="!item.children || item.children.length == 0" :index="` ${props.index} - ${item.meta.id}`"
            :key="`${props.index} - ${item.meta.id}`">
            <el-icon size="20">
                <component :is="item.meta.icon"></component>
            </el-icon>
            <span>{{ item.meta.name }}</span>
        </el-menu-item>
        <el-sub-menu v-else :index="` ${props.index} - ${item.meta.id}`" >
            <template #title>
                <el-icon size="20">
                    <component :is="item.meta.icon"></component>
                </el-icon>
                <span>{{ item.meta.name }}</span>
            </template>
            <tree-menu :index="` ${props.index} - ${item.meta.id}`" :menuData="item.children"  />
        </el-sub-menu>
    </template>
</template>

<style scoped></style>